package handles

import (
	"dev-team-mate/modle"
	"github.com/gin-gonic/gin"
)

func TableAdd(c *gin.Context) {
	tableName := c.PostForm("tableName")
	tableHome := c.PostForm("tableHome")
	if tableHome == "" || tableName == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}

	var table = modle.Table{
		TableName: tableName,
		TableHome: tableHome,
	}

	err := modle.DB.Debug().Create(&table).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 500,
		"msg":  "添加成功",
		"data": table,
	})
	return
}
